<%@ page language="java" %>
<%@page import="java.io.*,java.util.*,javax.persistence.*,javax.persistence.criteria.*,adventureWorks.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Hello World</title>
</head>
<body>
<%
java.io.PrintStream err = new java.io.PrintStream(new java.io.FileOutputStream("C:\\err.txt"));
try {
	
	err.println(Thread.currentThread().getContextClassLoader());
	String resource = "META-INF/persistence.xml";
	err.println(Thread.currentThread().getContextClassLoader().getResource(resource));
	err.flush();
	BufferedReader in = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResource(resource).openStream()));
	for (String line = in.readLine(); line != null; line = in.readLine()){
		err.println(line);
	}

	
	
	EntityManagerFactory emf=Persistence.createEntityManagerFactory("MyJspTest");
	EntityManager em=emf.createEntityManager();
	try{
		CriteriaBuilder queryBuilder = em.getCriteriaBuilder();
		Query q = em.createQuery("SELECT x FROM Customer x").setMaxResults(10);
		List<Customer> items = (List<Customer>) q.getResultList();

		session.setAttribute("items", items);
	} finally {
		em.close();
	}
} catch (Throwable e){
	e.printStackTrace(err);
	err.flush();
}
%>
<table border="1">
<tr>
<th>Company Name</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Phone</th>
<tr>
<c:forEach items="${items}" var="item">
<tr>
	<td>${item.companyName}</td>
	<td>${item.firstName}</td>
	<td>${item.lastName}</td>
	<td>${item.emailAddress}</td>
	<td>${item.phone}</td>
</tr>
</c:forEach>
</table>
</body>
</html>